package com.xhwl.centiotdata.pushtrigger.emergency;

import com.alibaba.fastjson.JSON;
import com.xhwl.centiotdata.handler.emergency.impl.EmergencyHuaWeiIoTDAHandler;
import com.xhwl.centiotdata.pojo.dto.emergency.EmergencyAlarm;
import com.xhwl.common.dto.cent.device.iot.DeviceServiceBody;
import com.xhwl.common.dto.cent.device.iot.IotDeviceJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: TODO
 * @author: chaoyun
 * @create: 2022/8/3 21:35
 **/
@Slf4j
@RestController
public class EmergencyCallback {
    @Autowired
    EmergencyHuaWeiIoTDAHandler handler;

    @PostMapping("/emergency/huawei-iotda/emergency/{projectId}")
    public void pushEmergency(@RequestBody IotDeviceJson<DeviceServiceBody<EmergencyAlarm>> data, @PathVariable Integer projectId) {
        log.debug("pushEmergency: " + JSON.toJSONString(data));
        handler.pushEmergency(data, projectId);
    }
}
